package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysTitle;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.website.SysTitleTreeModel;
import org.jeecg.modules.system.mapper.SysTitleMapper;
import org.jeecg.modules.system.model.DepartIdModel;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import org.jeecg.modules.system.service.ISysTitleService;
import org.jeecg.modules.system.util.FindsDepartsChildrenUtil;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 标题
 * @Author: jeecg-boot
 * @Date:   2024-06-19
 * @Version: V1.0
 */
@Service
public class SysTitleServiceImpl extends ServiceImpl<SysTitleMapper, SysTitle> implements ISysTitleService {


    @Override
    public List<SysTitleTreeModel> queryTreeList(String ids) {
        List<SysTitleTreeModel> listResult=new ArrayList<>();
        LambdaQueryWrapper<SysTitle> query = new LambdaQueryWrapper<SysTitle>();
        query.eq(SysTitle::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
        if(oConvertUtils.isNotEmpty(ids)){
            query.in(true,SysTitle::getId,ids.split(","));
        }
        query.orderByAsc(SysTitle::getBannerOrder);
        List<SysTitle> list= this.list(query);
        for (SysTitle depart : list) {
            listResult.add(new SysTitleTreeModel(depart));
        }
        return  listResult;
    }




    @Override
    public List<SysTitleTreeModel> queryTreeList() {
        LambdaQueryWrapper<SysTitle> query = new LambdaQueryWrapper<SysTitle>();
        query.eq(SysTitle::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
        query.orderByAsc(SysTitle::getBannerOrder);
        List<SysTitle> list = this.list(query);
        // 调用wrapTreeDataToTreeList方法生成树状数据
        List<SysTitleTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTree(list);
        return listResult;
    }




    @Override
    public List<DepartIdModel> queryTitleIdTreeList() {
        LambdaQueryWrapper<SysTitle> query = new LambdaQueryWrapper<SysTitle>();
        query.eq(SysTitle::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
        query.orderByAsc(SysTitle::getBannerOrder);
        List<SysTitle> list = this.list(query);
        // 调用wrapTreeDataToTreeList方法生成树状数据
        List<DepartIdModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToDepartIdTree(list);
        return listResult;
    }


}
